package com.st.mall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.st.mall.product.entity.CategoryEntity;
import com.st.mall.product.service.CategoryService;
import com.st.common.utils.R;



/**
 * 商品三级分类
 *
 * @author fg
 * @email f@163.com
 * @date 2023-02-26 20:46:23
 */
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = categoryService.queryPage(params);
        List<CategoryEntity> categoryEntities = categoryService.returnTree();
        return R.ok().put("page", categoryEntities);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")

    public R info(@PathVariable("catId") Long catId){
		CategoryEntity category = categoryService.getById(catId);

        return R.ok().put("category", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return R.ok();
    }

    /**
     * 拖拽数据修改，主要修改sort值
     * @param categoryEntities 拖拽后需要修改的节点数据
     *
     */
    @RequestMapping("/update/sort")
    public R batchUpdate(@RequestBody CategoryEntity[] categoryEntities){
        categoryService.updateBatchById(Arrays.asList(categoryEntities));
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody CategoryEntity category){
		categoryService.updateMore(category);

        return R.ok();
    }

    /**
     * 逻辑删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] catIds){
		categoryService.removeLogicByIds(Arrays.asList(catIds));
        return R.ok();
    }

}
